﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class delete_score : System.Web.UI.Page
{
    string Sno;
    string Sname;
    string Cno;
    string Cname;

    protected void Page_Load(object sender, EventArgs e)
    {
        Sno = Request.QueryString["Sno"];
        Sname = Request.QueryString["Sname"];
        Cno = Request.QueryString["Cno"];
        Cname = Request.QueryString["Cname"];

        Response.Write(" <h1>请确认删除'"+Sname+"'的'"+Cname+"'</h1> ");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string conn = "Data Source= . ;Initial Catalog=XSXK; User ID=sa; pwd=123";
        SqlConnection connection = new SqlConnection(conn);

        try
        {
            connection.Open();
            SqlCommand comm = new SqlCommand();
            comm.Connection = connection;

            string str_sql = " update result set score=NULL where Sno='"+Sno+"' and Cno='" + Cno + "' "; //删除学生成绩，设学生选课成绩为空，而不是删除此条选课信息
            comm.CommandText = str_sql;
            //comm.ExecuteScalar();  //如果为查询语句，则用ExecuteScalar()；否则，用ExecuteNonQuery()
            comm.ExecuteNonQuery();


            Response.Write("<h1>成功删除成绩信息！</h1>");
        }

        catch (SqlException ex)
        {
            Response.Write(ex.Message);
        }

        connection.Close();//关闭数据库连接
    }
}